package com.ppc.mapper.employer;

import com.github.pagehelper.Page;
import com.ppc.entity.Employer;
import com.ppc.entity.Recording;
import com.ppc.entity.Requirement;
import com.ppc.entity.TempTask;
import com.ppc.entity.Worker;
import com.ppc.vo.EmployerConfirm;
import com.ppc.vo.EmployerTaskQueryVO;
import com.ppc.vo.TaskDetail;
import com.ppc.vo.WorkerHandInResultVO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


/**
 * 雇主订单mapper层
 *
 * @author LENOVO
 * @date 2023/12/20
 */
@Mapper
public interface EmployerTaskMapper {

  /**
   * 分页查询订单
   * @param taskStatus
   * @param requireTitle
   * @param employerId
   * @return
   */
  Page<EmployerTaskQueryVO> taskPageQuery(String taskStatus, String requireTitle,Long employerId);



  /**
   * 雇主查看订单详细信息
   *
   * @param taskId
   * @return
   */
  TaskDetail checkTaskDetail(Long taskId);

  /**
   * 雇主查看工人提交结果
   *
   * @param taskId
   * @return
   */
  List<WorkerHandInResultVO> checkWorkerTask(Long taskId);

  /**
   * 雇主修改订单信息(创建tempTask表)
   *
   * @param tempTask
   * @return
   */
  void createTempTask(TempTask tempTask);

  /**
   * 雇主确认订单
   *
   * @param employerConfirm
   * @return
   */
  void confirm(EmployerConfirm employerConfirm);

  /**
   * 雇主发布需求
   *
   * @param taskId
   */
  void publish(Long taskId);

  /**
   * 更新雇主余额
   *
   * @param employerId
   * @param employerCount
   */
  void updateEmployerWallet(Long employerId, Float employerCount);

  /**
   * 获得需求
   *
   * @param taskId
   * @return {@link Requirement}
   */
  @Select("select re.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id where task_id = #{taskId}")
  Requirement getRequirementById(Long taskId);

  /**
   * 获得雇主
   *
   * @param taskId
   * @return {@link Employer}
   */
  @Select("select em.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id " +
      "LEFT JOIN employer em on em.employer_id = re.employer_id where task_id = #{taskId}")
  Employer getEmployerById(Long taskId);

  /**
   * 获取雇主id
   * @param userId
   * @return
   */
  @Select("select employer_id from employer where user_id=#{userId}")
  Long getEmployerIdByUserId(Long userId);

  /**
   * 获得订单状态
   *
   * @param taskId
   * @return int
   */
  @Select("select task_status from task where task_id=#{taskId}")
  int getTaskStatusById(Long taskId);

  /**
   * 获得worker
   *
   * @param taskId
   * @return {@link Worker}
   */
  @Select("select wo.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id " +
      "LEFT JOIN worker wo on wo.worker_id=ts.worker_id where task_id = #{taskId}")
  Worker getWorkerById(Long taskId);

  /**
   * 更新工人余额
   *
   * @param workerId
   * @param workerCount
   */
  void updateWorkerWallet(Long workerId, Float workerCount);

  /**
   * 创建金额记录
   *
   * @param recording
   */
  void createMoneyRecording(Recording recording);

  /**
   * 更新订单状态
   *
   * @param taskId
   * @param taskStatus
   */
  void updateTaskStatus(Long taskId, int taskStatus);

  /**
   * 获取雇主信誉
   * @param taskId
   * @return
   */
  @Select("select employer_credit from employer "
      + "left join requirement r on employer.employer_id = r.employer_id "
      + "LEFT JOIN task t on r.require_id = t.require_id "
      + "where t.task_id=#{taskId}")
  int getCredit(Long taskId);

  /**
   * 更改需求状态
   * @param requireStatus
   */
  void setRequireStatus(Integer requireStatus,Long requireId);
}
